<template>
  <el-form
    ref="ruleFormRef"
    style="max-width: 600px"
    :model="ruleForm"
    :rules="rules"
    label-width="auto"
  >
    <el-form-item label="权限名称" prop="permissionName">
      <el-input v-model="ruleForm.permissionName" />
    </el-form-item>

    <el-form-item label="权限Url" prop="permissionUrl">
      <el-input v-model="ruleForm.permissionUrl" />
    </el-form-item>

    <el-form-item label="权限序号" prop="number">
      <el-input v-model="ruleForm.number" />
    </el-form-item>

    <el-form-item>
      <el-button type="primary" @click="submitForm(ruleFormRef)">
        保存
      </el-button>
      <el-button @click="resetForm(ruleFormRef)">取消</el-button>
    </el-form-item>
  </el-form>
</template>

<script lang="ts" setup>
import { reactive, ref } from 'vue'

import { ElMessage, type FormInstance, type FormRules } from 'element-plus'
import {wrire} from '../Until/axiosHelp'
interface RuleForm {
  "permissionName": "",
  "permissionUrl": "",
  "number": ""
}

const ruleFormRef = ref<FormInstance>()
const ruleForm = reactive<RuleForm>({
  "permissionName": "",
  "permissionUrl": "",
  "number": ""
})

const locationOptions = ['Home', 'Company', 'School']

const rules = reactive<FormRules<RuleForm>>({
  permissionName: [
    { required: true, message: '权限名称不能为空', trigger: 'blur' },
   
  ],
  permissionUrl: [
    {
      required: true,
      message: '权限URL不能为空',
      trigger: 'change',
    },
  ],
  number: [
    {
      required: true,
      message: '权限序号不能为空',
      trigger: 'change',
    },
  ],
  
})

const submitForm = async (formEl: FormInstance | undefined) => {
  if (!formEl) return
  await formEl.validate((valid, fields) => {
    if (valid) {
    console.log('submit!')
    wrire.post("api/Query/PermissionAdd",ruleForm).then(res=>{
    if(res.data.code==200)
    {
        ElMessage.success(res.data.msg)
        
    }
    else{
        ElMessage.error(res.data.msg)
    }
    })
    } else {
      console.log('error submit!', fields)
    }
  })
}

const resetForm = (formEl: FormInstance | undefined) => {
  if (!formEl) return
  formEl.resetFields()
}

const options = Array.from({ length: 10000 }).map((_, idx) => ({
  value: `${idx + 1}`,
  label: `${idx + 1}`,
}))
</script>
